package praktikumid.w10.p5;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;

/**
 * Abstract class for all the shapes. We extend MouseAdapter
 * here, which has all the methods for mouse events. That
 * way we don't need to define those here.
 * @author Ago
 *
 */
public abstract class Shape extends MouseAdapter {
	/**
	 * Constant for active color.
	 */
	public static final Color ACTIVE_COLOR = Color.RED;
	/**
	 * Constant for default color.
	 */
	public static final Color DEFAULT_COLOR = Color.BLACK;
	
	/**
	 * Color of the shape.
	 */
	private Color color = DEFAULT_COLOR;
	
	/**
	 * Whether the shape is finished.
	 */
	protected boolean isFinished = false;
	
	/**
	 * Whether the shape is active
	 */
	protected boolean isActive = false;
	
	/**
	 * Get method for the isActive
	 * @return Whether the shape is active
	 */
	public boolean isActive() {
		return isActive;
	}

	/**
	 * Set method for isActive, should not be used
	 * @param isActive
	 */
	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	/**
	 * Whether the shape is finished?
	 * @return
	 */
	public boolean isFinished() {
		return isFinished;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	/**
	 * Paint method for the shape. Every shape
	 * should know how to paint itself.
	 * @param g
	 */
	public void paint(Graphics g) {
		if (isActive) {
			g.setColor(ACTIVE_COLOR);
		} else {
			g.setColor(color);
		}
		paintComponent(g);
	}
	
	/**
	 * Every shape should override this method.
	 * @param g Graphics of the panel
	 */
	protected abstract void paintComponent(Graphics g);
	/**
	 * Get distance from specified point.
	 * @param p
	 * @return
	 */
	public abstract int getDistance(Point p);
	/**
	 * Move the shape according to the delta x and delta y.
	 * @param dx
	 * @param dy
	 */
	public abstract void move(int dx, int dy);
}
